/**
 * SIX VULN - http://code.google.com/p/six-vuln/
 * Copyright (C) 2006
 *   National Institute of Advanced Industrial Science and Technology (AIST)
 *   Registration Number: H20PRO-863
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package jp.go.aist.six.vuln.model.scap.vulnerability;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import jp.go.aist.six.vuln.model.scap.core.CheckReferenceType;




/**
 *
 * @author	Akihito Nakamura, AIST
 * @version $Id: ToolConfigurationType.java 529 2013-04-15 07:08:54Z nakamura5akihito@gmail.com $
 */
public class ToolConfigurationType
    implements Serializable
{

    /**
     * The CPE name of the scanning tool.
     * A value must be supplied for this element.
     * The CPE name can be used for a CPE from the NVD.
     * The CPE title attribute can be used for internal naming conventions.
     * (or both, if possible)
     */
    private String  name;
    //{0..1, scap-core:CpeNamePatternType}


    /**
     * Defines required signature or policy definition that must be installed on the tool.
     */
    private final Collection<CheckReferenceType>  definition = new ArrayList<CheckReferenceType>();
    //{0..*}



    /**
     *
     */
    public ToolConfigurationType()
    {
    }



    public String getName()
    {
        return name;
    }



    public void setName(
                    final String name
                    )
    {
        this.name = name;
    }



    /**
     */
    public Collection<CheckReferenceType> getDefinition()
    {
        return definition;
    }


    public void setDefinition(
                    final Collection<? extends CheckReferenceType> definition_list
                    )
    {
        if (definition_list != definition) {
            definition.clear();
            if (definition_list != null) {
                definition.addAll( definition_list );
            }
        }
    }



    //*********************************************************************
    //  java.lang.Object
    //*********************************************************************

    @Override
    public int hashCode()
    {
        final int prime = 37;
        int result = 17;

        final String  name = getName();
        final Collection<CheckReferenceType>  definition = getDefinition();

        result = prime * result + ((name == null) ? 0 : name.hashCode());
        result = prime * result + ((definition == null) ? 0 : definition.hashCode());

        return result;
    }



    @Override
    public boolean equals(
                    final Object obj
                    )
    {
        if (this == obj) {
            return true;
        }

        if (!(obj instanceof ToolConfigurationType)) {
            return false;
        }

        final ToolConfigurationType  other = (ToolConfigurationType)obj;

        final String   this_name =  this.getName();
        final String  other_name = other.getName();
        if (this_name == other_name
                        ||  (this_name != null  &&  this_name.equals( other_name ))) {
            final Collection<CheckReferenceType>   this_definition =  this.getDefinition();
            final Collection<CheckReferenceType>  other_definition = other.getDefinition();
            if (this_definition == other_definition
                            ||  (this_definition != null  &&  other_definition != null
                            &&  this_definition.size() == other_definition.size()
                            &&  this_definition.containsAll( other_definition ))) {
                return true;
            }
        }

        return false;
    }



    @Override
    public String toString()
    {
        return "ToolConfigurationType[name="    + getName()
                        + ", definition="       + getDefinition()
                        + "]";
    }

}
//ToolConfigurationType
